<?php
	####################################################
	# Elapsed 퍼포먼스 체크                            #
	####################################################

	class Elapsed{
		# 어플리케이션의 퍼포먼스 체크용 입니다.
		# $elapsed_start = get_time();
		# $elapsed_end = get_time();
		# $time = $elapsed_end - $elapsed_start;
		# echo '<br/>'.$time.'초 걸림';
		public static function get_time() {
			list($usec, $sec) = explode(" ", microtime());
			return ((float)$usec + (float)$sec);
		}

		public static function view_time($rtime) {
			$cnt = count($rtime);
			for ($i=1;$i<$cnt;$i++) $ret[] = get_microtime($rtime[$i-1],$rtime[$i]);
			echo "
			<table width=150 border=1 bordercolor='#cccccc' style='border-collapse:collapse' style='font:8pt tahoma'>
			<tr bgcolor='#f7f7f7'>
				<th width=40 nowrap>no</th>
				<th width=100%>time</th>
			</tr>
			<col align=center span=2>
			";
			foreach ($ret as $k=>$v) echo "<tr><td>".($k+1)."</td><td>$v</td></tr>";
			if ($cnt>2){
				$total = get_microtime($rtime[0],$rtime[$cnt-1]);
				echo "<tr bgcolor='#f7f7f7'><td>total</td><td>$total</td></tr>";
			}
			echo "</table>";
		}

		# 시간 측정
		public static function get_microtime($old,$new) {
			$old = explode(" ", $old);
			$new = explode(" ", $new);
			$time[msec] = $new[0] - $old[0];
			$time[sec]  = $new[1] - $old[1];
			if($time[msec] < 0) {
				$time[msec] = 1.0 + $time[msec];
				$time[sec]--;
			}
			$ret = $time[sec] + $time[msec];
			return $ret;
		}

		# datetime -> timestamp
		public static function toTimeStamp($datetime){
			$y = substr($datetime,0,4);	$m = substr($datetime,5,2);	$d = substr($datetime,8,2);
			$h = substr($datetime,11,2);	$i = substr($datetime,14,2);	$s = substr($datetime,17,2);
			return mktime($h, $i, $s, $m, $d, $y);
		}
	}
?>